﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bll;
using Help;
using Model;

namespace Myproject.BSM.Ashx.PcChannel
{
    /// <summary>
    /// GoodsCertificateEdit 的摘要说明
    /// </summary>
    public class GoodsCertificateEdit : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Form["pc_Channel_GoodsCertificateEdit_GoodsCertificateId"];
            string gid = context.Request.Form["pc_Channel_GoodsCertificateEdit_GoodsID"];
            string loadurl = context.Request.Form["doc_pic"];
            string rank = context.Request.Form["pc_Channel_GoodsCertificateEdit_rank"];
            if (id == "0")
            {
                GoodsCertificateModel model = new GoodsCertificateModel();
                model.GoodsID = int.Parse(gid);
                model.Loadurl = loadurl;
                model.GoodsCertificateShow = true;
                model.GoodsCertificateRank = int.Parse(rank);

                if (new GoodsCertificateBLL().Add(model) > 0)
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "添加资料成功！", "pc_base_CertificateList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "添加资料失败！", "pc_base_CertificateList", "", "", true, "", ""));
                }
            }
            else
            {
                GoodsCertificateModel model = new GoodsCertificateBLL().GetModel(int.Parse(id));
                model.GoodsID = int.Parse(gid);
                model.Loadurl = loadurl;
                model.GoodsCertificateShow = true;
                model.GoodsCertificateRank = int.Parse(rank);
                if (new GoodsCertificateBLL().Update(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改资料成功！", "pc_base_CertificateList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改资料失败！", "pc_base_CertificateList", "", "", true, "", ""));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}